/* $Id:plan.h $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/

#ifndef __PLAN_H
#define __PLAN_H

#include <string>
#include <map>
#include <list>
using namespace std;

#include "contributers.h"
#include "contractors.h"

#define loopPlanContributers(r,v) loopMap((r)->listContributers(),v,class contributers)
#define loopPlanPersons(r,v) loopMap((r)->listPersons(),v,class contractors)

class plan {
    int nr;
    int type;
    int planned;
    int finished;
    int done;
    class army *what;
    map<string,class contributers> contributers;
    map<string,class contractors> persons;
    int priority;
    int location;
public:
    plan();

    // Field : nr
    const int getNr() const;
    void setNr(const int v);
    int operator<(const class plan &ck) const;

    // Field : type
    enum type_enum{type_create,type_patrol,type_defend,type_destroy,type_pillage,type_conquer,type_scout,type_trade};
    const int getType() const;
    const string showType() const;
    void setType(const int v);
    void setType(const string v);

    // Field : planned
    const int getPlanned() const;
    void setPlanned(const int v);

    // Field : finished
    const int getFinished() const;
    void setFinished(const int v);

    // Field : done
    const int getDone() const;
    void setDone(const int v);

    // Field : what
    class army& getWhat() const;
    void setWhat(class army &v);

    // Field : contributers
    class contributers& getContributers(const string v);
    map<string,class contributers>& listContributers();
    void setContributers(class contributers &v);
    void delContributers(const string v);
    const bool isContributers(const string v) const;

    // Field : persons
    class contractors& getPersons(const string v);
    map<string,class contractors>& listPersons();
    void setPersons(class contractors &v);
    void delPersons(const string v);
    const bool isPersons(const string v) const;

    // Field : priority
    const int getPriority() const;
    void setPriority(const int v);

    // Field : location
    const int getLocation() const;
    void setLocation(const int v);
    const string showLocation() const;

    void save(class channel &ch);
    void load(class channel &ch);
    void xml(ofstream &f, int l=0, int r=0);
};

// Repository

#define loopPlans(v) loopMapi(plan_repo.listPlan(),v,class plan)

class planRepository {
    map<int,class plan> plans;
    int max_nr;
public:
    planRepository();
    class plan& getPlan(const int v);
    void setPlan(class plan& v);
    map<int,class plan>& listPlan();
    void delPlan(const int v);
    const bool isPlan(const int v) const;
    bool load(class channel &ch);
    void save(class channel &ch);
};

extern planRepository plan_repo;

#endif // __PLAN_H
